﻿// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/ContentWidget.h"
#include "Components/ElementUISlot.h"
#include "ElementUIFilletButton.generated.h"

class SFilletButton;

UCLASS(meta=(DisplayName="Fillet Button"))
class ELEMENTUIUMG_API UElementUIFilletButton : public UContentWidget
{
	GENERATED_BODY()
public:
	UElementUIFilletButton();
	virtual void SynchronizeProperties() override;
	virtual void ReleaseSlateResources(bool bReleaseChildren) override;
	virtual void PostLoad() override;

	UFUNCTION(BlueprintCallable,Category="ElementUI|FilletButton")
	FText GetText() { return Text; }

	UFUNCTION(BlueprintCallable,Category="ElementUI|FilletButton")
	void SetText(FText value);

	UFUNCTION(BlueprintCallable,Category="ElementUI|FilletButton")
	void SetDisabled(bool value);

#if WITH_EDITOR
	virtual const FText GetPaletteCategory() override { return NSLOCTEXT("ElementUI", "ElementUICategory", "ElementUI"); }
#endif

protected:
	virtual TSharedRef<SWidget> RebuildWidget() override;
	FReply SlateHandleClicked();
	void SlateHandleHovered();
	void SlateHandleUnhovered();

	virtual UClass* GetSlotClass() const override;
	virtual void OnSlotAdded(UPanelSlot* Slot) override;
	virtual void OnSlotRemoved(UPanelSlot* Slot) override;
	
private:
	UMaterialInstanceDynamic* GetDynamicMaterial();
	void SetUseImage(bool value);
	void UpdateBrush();

private:
	DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnFilletButtonClickedEvent);
	DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnFilletButtonHoverEvent);

	TSharedPtr<SFilletButton> FilletButtonSlate;

private:
	FSlateBrush IconBrush;
	bool HaveChild;

	UPROPERTY(EditAnywhere, Category=FilletButton,meta = (AllowPrivateAccess = "true", MultiLine="true"))
	FText Text;

	UPROPERTY(EditAnywhere, Category=FilletButton,meta = (AllowPrivateAccess = "true"))
	FSlateFontInfo TextFont;

	UPROPERTY(EditAnywhere, Category=FilletButton,meta = (AllowPrivateAccess = "true"))
	TEnumAsByte<EHorizontalAlignment> TextHAlign;
	
	UPROPERTY(EditAnywhere, Category=FilletButton,meta = (AllowPrivateAccess = "true"))
	TEnumAsByte<EVerticalAlignment> TextVAlign;
	
	UPROPERTY(EditAnywhere, Category=FilletButton,meta = (AllowPrivateAccess = "true"))
	FLinearColor TextColor;
	
	UPROPERTY(EditAnywhere, Category=FilletButton,meta = (AllowPrivateAccess = "true", ClampMin="0", ClampMax="1"))
	float Radius;

	UPROPERTY(EditAnywhere, Category=FilletButton,meta = (AllowPrivateAccess = "true"))
	FVector2D RadiusSize;

	UPROPERTY(EditAnywhere, Category=FilletButton,meta = (AllowPrivateAccess = "true", ClampMin="0", ClampMax="1", EditCondition="!UseImage", EditConditionHides))
	float BorderWidth;

	UPROPERTY(EditAnywhere, Category=FilletButton,meta = (AllowPrivateAccess = "true", EditCondition="!UseImage", EditConditionHides))
	FLinearColor BorderColor;

	UPROPERTY(EditAnywhere, Category=FilletButton,meta = (AllowPrivateAccess = "true", ClampMin="0", EditCondition="!UseImage", EditConditionHides))
	float BorderSharpness;

	UPROPERTY(EditAnywhere, Category=FilletButton,meta = (AllowPrivateAccess = "true", ClampMin="0", ClampMax="1", EditCondition="!UseImage", EditConditionHides))
	float BorderOpacity;

	UPROPERTY(EditAnywhere, Category=FilletButton,meta = (AllowPrivateAccess = "true", EditCondition="!UseImage", EditConditionHides))
	FLinearColor BackgroundColor;

	UPROPERTY(EditAnywhere, Category=FilletButton,meta = (AllowPrivateAccess = "true", ClampMin="0", ClampMax="1", EditCondition="!UseImage", EditConditionHides))
	float BackgroundOpacity;

	UPROPERTY(EditAnywhere, Category=FilletButton,meta = (AllowPrivateAccess = "true"))
	bool Disabled;

	UPROPERTY(EditAnywhere, Category=FilletButton,meta = (AllowPrivateAccess = "true"))
	bool UseImage;

	UPROPERTY(BlueprintAssignable, Category=FilletButton, meta= (AllowPrivateAccess = "true"))
	FOnFilletButtonClickedEvent OnClicked;

	UPROPERTY(BlueprintAssignable, Category=FilletButton, meta= (AllowPrivateAccess = "true"))
	FOnFilletButtonHoverEvent OnHovered;

	UPROPERTY(BlueprintAssignable, Category=FilletButton, meta= (AllowPrivateAccess = "true"))
	FOnFilletButtonHoverEvent OnUnhovered;
};
